package com.example.adminui.controller;

import com.example.adminui.entity.Team;
import com.example.adminui.service.TeamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 团队管理控制器
 * <p>提供团队相关的CRUD操作API接口</p>
 */
@RestController
@RequestMapping("/api/teams")
public class TeamController {
    @Autowired
    private TeamService teamService;

    /**
     * 获取所有团队信息
     * @return 团队列表
     */
    @GetMapping
    public List<Team> getAllTeams() {
        return teamService.getAllTeams();
    }

    /**
     * 根据ID获取团队信息
     * @param id 团队ID
     * @return 团队对象
     */
    @GetMapping("/{id}")
    public Team getTeamById(@PathVariable Long id) {
        return teamService.getTeamById(id);
    }

    /**
     * 创建新团队
     * @param team 团队对象
     */
    @PostMapping
    public void createTeam(@RequestBody Team team) {
        teamService.createTeam(team);
    }

    /**
     * 更新团队信息
     * @param id 团队ID
     * @param team 团队对象
     */
    @PutMapping("/{id}")
    public void updateTeam(@PathVariable Long id, @RequestBody Team team) {
        team.setId(id);
        teamService.updateTeam(team);
    }

    /**
     * 删除团队
     * @param id 团队ID
     */
    @DeleteMapping("/{id}")
    public void deleteTeam(@PathVariable Long id) {
        teamService.deleteTeam(id);
    }
}